import { POST } from '../axios.config.js'

const base = window.config.ip
const baseUrl = `${base}/rcdg-model`
const baseUrl1 = `${base}/public-uias-api`

const URLS = {
  listTopModel: `${baseUrl}/simple-model/listTopModel`, // 获取指标模型列表
  initModelTree: `${baseUrl}/simple-model/initModelTree`, // 根据租户id初始化模型树
  getModelTreeInfo: `${baseUrl}/simple-model/getModelTreeInfo`, // 根据模型id获取模型树
  getModelData: `${baseUrl}/simple-model/getModelData`, // 获取模型数据
  getTargetData: `${baseUrl}/simple-model/getTargetData`, // 获取指标数据
  saveModelData: `${baseUrl}/simple-model/saveModelData`, // 保存模型数据
  saveTargetData: `${baseUrl}/simple-model/saveTargetData`, // 保存指标数据
  addSubordinate: `${baseUrl}/simple-model/addSubordinate`, // 添加下级指标/模型
  addSibling: `${baseUrl}/simple-model/addSibling`, // 添加同级指标/模型
  copyCreate: `${baseUrl}/simple-model/copyCreate`, // 复制创建指标/模型
  deleteModel: `${baseUrl}/simple-model/delete`, // 删除指标/模型
  keepModelInFile: `${baseUrl}/simple-model/keepModelInFile`, // 模型存档
  getPreviewData: `${baseUrl}/simple-model/getPreviewData`, // 获取评价预览数据
}

const URLS1 = {
  getTenantList: `${baseUrl1}/uias-tenant/getTenantList`,
}

export const getTenantList = () =>
  POST(URLS1.getTenantList, {
    occurrenceTime: '',
    oneParam: '',
    tenantId: localStorage.pskh_tenantId,
    userInfoBusType: '',
  })

export const listTopModel = ({ productId, tenantId, modelStr, modelState, currentPage = 1, pageSize = 10 }) =>
  POST(
    URLS.listTopModel,
    {
      productId,
      tenantId: localStorage.pskh_tenantId,
      modelStr,
      modelState,
      current: currentPage,
      size: pageSize,
    },
    {
      headers: {
        'content-Type': 'application/x-www-form-urlencoded',
      },
    }
  )

export const initModelTree = tenantId =>
  POST(URLS.initModelTree, {
    tenantId: localStorage.pskh_tenantId,
  })

export const getModelTreeInfo = id =>
  POST(URLS.getModelTreeInfo, {
    id,
  })

export const getModelData = id =>
  POST(URLS.getModelData, {
    id,
  })

export const getTargetData = id =>
  POST(URLS.getTargetData, {
    id,
  })

export const saveModelData = ({ assessInfo, id, modelAlias, modelDescribe, modelName, modelNum, modelScore }) =>
  POST(URLS.saveModelData, {
    assessInfo,
    id,
    modelAlias,
    modelDescribe,
    modelName,
    modelNum,
    modelScore,
  })

export const saveTargetData = ({
  assessInfo,
  id,
  optionEntityRequests = [],
  targetAlias,
  targetDescribe,
  targetName,
  targetNum,
  targetScore,
}) =>
  POST(URLS.saveTargetData, {
    assessInfo,
    id,
    optionEntityRequests,
    targetAlias,
    targetDescribe,
    targetName,
    targetNum,
    targetScore,
  })

export const addSubordinate = ({ id, type }) =>
  POST(URLS.addSubordinate, {
    id,
    type,
  })

export const addSibling = ({ id, type }) =>
  POST(URLS.addSibling, {
    id,
    type,
  })

export const copyCreate = id =>
  POST(URLS.copyCreate, {
    id,
  })

export const deleteModel = id =>
  POST(URLS.deleteModel, {
    id,
  })

export const keepModelInFile = id =>
  POST(URLS.keepModelInFile, {
    id,
  })

export const getPreviewData = id =>
  POST(URLS.getPreviewData, {
    id,
  })
